package com.tj.collection.controller.lending.response;

import com.fqgj.common.api.ResponseData;
import com.tj.collection.db.entity.business.ClCallInfoEntity;
import com.tj.collection.utils.IndiaMobileUtil;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2020/3/23
 * Time: 下午8:33
 */
public class ClCallDurationInfoResponse implements ResponseData {

    private List<Item> callDurationList;

    private List<String[]> itemList;

    public ClCallDurationInfoResponse(List<ClCallInfoEntity> entityList) {
        this.callDurationList = new ArrayList<>();
        for (ClCallInfoEntity entity : entityList) {
            Item item = new Item();
            BeanUtils.copyProperties(entity, item);
            item.setFamilyMobile(IndiaMobileUtil.countryCodeFilter(item.getFamilyMobile()));
            item.setFriendMobile(IndiaMobileUtil.countryCodeFilter(item.getFriendMobile()));
            item.setTradeNo(entity.getOrderNo());
            item.setDialed("NO");
            if (entity.getCallDuration() != null) {
                item.setDialed("YES");
            }
            this.callDurationList.add(item);
        }
    }

    public ClCallDurationInfoResponse(List<ClCallInfoEntity> entityList, boolean isExport) {
        this.itemList = new ArrayList<>();
        String[] row1 = {
                "Loan ID", "Loan Amount", "Customer Name", "Agent Name", "Customer Mobile Number",
                "Dialed or Not", "Start time", "End time", "Call Duration", "Reference 1",
                "Reference 2"
        };

        this.itemList.add(row1);

        for (ClCallInfoEntity entity : entityList) {
            String[] row = new String[row1.length];
            row[0] = entity.getOrderNo();
            row[1] = entity.getBorrowCapital();
            row[2] = entity.getName();
            row[3] = entity.getFollowUp() + " [" + entity.getFollowId() + "]";
            row[4] = entity.getMobile();
            row[5] = entity.getCallDuration() != null ? "YES" : "NO";
            row[6] = entity.getStartTime();
            row[7] = entity.getEndTime();
            row[8] = entity.getCallDuration() == null ? "" : (entity.getCallDuration() + "");
            row[9] = IndiaMobileUtil.countryCodeFilter(entity.getFamilyMobile());
            row[10] = IndiaMobileUtil.countryCodeFilter(entity.getFriendMobile());
            this.itemList.add(row);
        }
    }

    private class Item {
        /**
         * 订单号
         */
        private String tradeNo;
        /**
         * 借款金额
         */
        private String borrowCapital;
        /**
         * 用户名字
         */
        private String name;
        /**
         * 跟进人
         */
        private Integer followId;
        /**
         * 跟进人
         */
        private String followUp;
        /**
         * 被呼叫的号码
         */
        private String mobile;
        /**
         * 是否接通 YES/NO
         */
        private String dialed;
        /**
         * 起始时间
         */
        private String startTime;
        /**
         * 结束时间
         */
        private String endTime;
        /**
         * 通话时长 秒
         */
        private Integer callDuration;
        /**
         * 联系人号码1
         */
        private String familyMobile;
        /**
         * 联系人号码2
         */
        private String friendMobile;

        public String getTradeNo() {
            return tradeNo;
        }

        public Item setTradeNo(String tradeNo) {
            this.tradeNo = tradeNo;
            return this;
        }

        public String getBorrowCapital() {
            return borrowCapital;
        }

        public Item setBorrowCapital(String borrowCapital) {
            this.borrowCapital = borrowCapital;
            return this;
        }

        public String getName() {
            return name;
        }

        public Item setName(String name) {
            this.name = name;
            return this;
        }

        public Integer getFollowId() {
            return followId;
        }

        public Item setFollowId(Integer followId) {
            this.followId = followId;
            return this;
        }

        public String getFollowUp() {
            return followUp;
        }

        public Item setFollowUp(String followUp) {
            this.followUp = followUp;
            return this;
        }

        public String getMobile() {
            return mobile;
        }

        public Item setMobile(String mobile) {
            this.mobile = mobile;
            return this;
        }

        public String getDialed() {
            return dialed;
        }

        public Item setDialed(String dialed) {
            this.dialed = dialed;
            return this;
        }

        public String getStartTime() {
            return startTime;
        }

        public Item setStartTime(String startTime) {
            this.startTime = startTime;
            return this;
        }

        public String getEndTime() {
            return endTime;
        }

        public Item setEndTime(String endTime) {
            this.endTime = endTime;
            return this;
        }

        public Integer getCallDuration() {
            return callDuration;
        }

        public Item setCallDuration(Integer callDuration) {
            this.callDuration = callDuration;
            return this;
        }

        public String getFamilyMobile() {
            return familyMobile;
        }

        public Item setFamilyMobile(String familyMobile) {
            this.familyMobile = familyMobile;
            return this;
        }

        public String getFriendMobile() {
            return friendMobile;
        }

        public Item setFriendMobile(String friendMobile) {
            this.friendMobile = friendMobile;
            return this;
        }
    }

}
